import 'package:dashboard/dio/dio_gateway.dart';
import 'package:flutter/material.dart';

class Channel extends StatefulWidget {
  const Channel({super.key});

  @override
  State<Channel> createState() => _ChannelState();
}

class _ChannelState extends State<Channel> {
  late List<String> channels = [];

  Future<void> future() async {
    channels = await GateWayDio.GetChannels();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: future(),
        builder: (builder, snapshot) {
          return SizedBox(
            width: MediaQuery.of(context).size.width,
            child: Card(
              color: Colors.white,
              elevation: 1,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(5),
              ),
              margin: const EdgeInsets.all(20),
              child: DataTable(
                columns: const <DataColumn>[
                  DataColumn(
                    label: Expanded(
                      child: Text(
                        '频道',
                        style: TextStyle(
                          fontStyle: FontStyle.italic,
                        ),
                      ),
                    ),
                  ),
                  DataColumn(
                    label: Expanded(
                      child: Text(
                        '操作',
                        style: TextStyle(fontStyle: FontStyle.italic),
                      ),
                    ),
                  ),
                ],
                rows: <DataRow>[
                  ...List.generate(
                    channels.length,
                    (index) => DataRow(
                      cells: <DataCell>[
                        DataCell(Text(channels[index])),
                        DataCell(
                          Icon(Icons.edit),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
        });
  }
}
